<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>


<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
    });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="css/Tree.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="lib/datatables/js/jquery.dataTables.js"></script>
<!-- DATATABLES CSS END -->

<div class="container_12 clearfix leading">
    <div id="demo" class="clearfix">
        <table class="display" id="example">
            <thead>
            <tr>
                <th>选择</th>
                <th>项目名称</th>
                <th>项目内容</th>
                <th>审核人</th>
                <th>备注</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <s:if test="#request.projects == null or #request.projects.size() == 0">
                <tr class="gradeX"><td colspan="6">暂无数据</td></tr>
            </s:if>
            <s:else>
                <s:iterator value="#request.projects" var="p" status="sta">
                <tr class='grade${sta.even ? "A" : "C"}'>
                    <td><input type="checkbox" id="form-updates" value="${p.id}" name="chk_projects_${organizationId}"/></td>
                    <td>${p.name}</td>
                    <td>${p.content}</td>
                    <td>${p.auditor.name}</td>
                    <td>${p.remark}</td>
                    <td>
                        <a href="#leave/project-edit.xhtml?project.id=${p.id}&t=<%=new Date()%>" class="button"><span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>修改</a>
                    </td>
                </tr>
                </s:iterator>
            </s:else>
            </tbody>
        </table>
    </div>
</div>
<div class="clear"></div>
<div class="tabs side grid_12 leading">
    <div class="clear"></div>
    <div class="grid_12">
        <div class="form-action clearfix">
            <p>
            <div class="checker" id="uniform-form-updates2"><span><input type="checkbox" value="1" id="form-updates2" style="opacity: 0;"></span></div>全选
            <button type="button" class="button" onclick="deleteProject()">批量删除</button>
            <a class="button" href="#leave/project-create.xhtml?organizationId=${organizationId}&t=<%=new Date()%>"><span style="background:url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>添加</a>
            </p>
        </div>
    </div>
</div>

<div class="clear"></div>

<script type="text/javascript">
    function findCheckProject(){
        var checkIds = new Array();
        $("input[type='checkbox'][name='chk_projects_${organizationId}']").each(function(){
            if(this.checked){
                checkIds.push(this.value);
            }
        });
        alert(checkIds)
        return checkIds;
    }

    function edit(){
        var checkIds = findCheckProject();
        if(checkIds.length == 0){
            alert("请选择要修改的数据")
            return;
        }
        window.location.href = "#leave/project-create.xhtml?organizationId=${organizationId}&project.id="+checkIds[0];
    }

    function add(){
        window.location.href = "#leave/project-create.xhtml?organizationId=${organizationId}";
    }

    function deleteProject(){
        var checkIds = findCheckProject();
        if(checkIds.length == 0){
            alert("请选择要删除的数据")
            return;
        }
        if(confirm("确定要删除选择的离职项目数据吗")){
            window.location.href = "#leave/project-delete.xhtml?organizationId=${organizationId}&project_ids="+checkIds.join(",");
        }
    }
</script>